package cn.ac.iscas.service.paper;

import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.ac.iscas.bean.base.DAOSupport;
import cn.ac.iscas.bean.paper.Paper;
import cn.ac.iscas.bean.paper.PaperDocument;
import cn.ac.iscas.bean.project.Project;
@Service
@Transactional
public class PaperServiceImp extends DAOSupport<Paper> implements IPaperService {
	@Resource private IPaperDocumentService paperDocumentService;
	
	public Set<Project> getProjects(Class<Paper> entityClass,int entityId)
	{
		return ((Paper)sessionFactory.getCurrentSession().get(entityClass,entityId)).getProjects();
	}
	/* (non-Javadoc)
	 * @see cn.ac.iscas.bean.base.DAOSupport#delete(java.lang.Object)
	 */
	@Override
	public void delete(Object entity) {
		Paper paper= (Paper)entity;
		Set<PaperDocument> docs = paper.getPdf();
		for(PaperDocument file:docs)
		{
			System.out.println(file.getDocName());
			paperDocumentService.delete(file);
		}
		super.delete(paper);
	}
	
}
